package com.fairytask.logic
{
	import com.fairytask.GameStage;
	import com.fairytask.data.Modulator;
	import com.fairytask.event.SceneEvent;
	import com.fairytask.scene.BattleScene;
	
	import starling.display.DisplayObject;

	/**
	 * 场景切换逻辑 
	 * @author game
	 * 
	 */	
	public class SceneLogic
	{
		private static var _instance	:SceneLogic;
		private var model:Modulator;
		
		public static function get instance():SceneLogic
		{
			if(null==_instance)
			{
				_instance	=	new SceneLogic();
			}
			return _instance;
		}

		public function SceneLogic()
		{
			model	=	Modulator.instance;
			initEvent();
		}
		
		private function initEvent():void
		{
			model.addEventListener(SceneEvent.START_SCENE,onSwitchScene);
		}
		
		/**
		 * 切换场景 
		 * @param evt
		 */
		private function onSwitchScene(evt:SceneEvent):void
		{
			while(GameStage.sceneSpace.numChildren>0)
			{
				GameStage.sceneSpace.removeChildAt(0);
			}
			
			GameStage.sceneSpace.addChild(evt.scene as DisplayObject);
		}
	}
}